package com.eras.shoes.view;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.TextView;

import com.eras.shoes.R;

public class RxDialogWriteSureCancel extends RxDialog {

    public TextView mTvTitle;
    public TextView mTvContent;
    public TextView mTvCancel;
    public TextView mTvSure;
    public View mViewLine;
    public TextView dialogTvWriteShoesTypeValue;
    public TextView dialogTvWriteSerialTypeValue;
    public TextView dialogTvWriteShoesColorValue;
    public TextView dialogTvWriteShoesSizeValue;
    public TextView dialogTvWriteCompanyValue, dialogTvWriteCodeWordValue, dialogTvWriteSpecificationValue;
    public TextView dialogTvWriteFootTypeValue,dialogTvWriteFootTypeLeft,dialogTvWriteFootTypeRight;
    public ImageView ivDialogTvWriteCompany,ivDialogTvWriteCodeWord,ivDialogTvWriteShoesType,ivDialogTvWriteSerialType,ivDialogTvWriteShoesColor,ivDialogTvWriteShoesSize,ivDialogTvWriteSpecification;

    public LinearLayout dialogLlWriteShoesType, dialogLlWriteSerialType, dialogLlWriteShoesColor, dialogLlWriteShoesSize, dialogLlWriteCompany, dialogLlWriteCodeWord, dialogLlWriteSpecification;
    @SuppressLint("HandlerLeak")
    public Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            if (msg.what == 0 && mTvContent != null) {
                mTvContent.setText(msg.obj.toString());
            } else if (msg.what == 1 && mTvTitle != null) {
                if (mTvTitle.getVisibility() == View.GONE) {
                    mTvTitle.setVisibility(View.VISIBLE);
                }
                mTvTitle.setText(msg.obj.toString());
            }
        }
    };

    public RxDialogWriteSureCancel(Context context, int themeResId) {
        super(context, themeResId);
        initView();
    }

    public RxDialogWriteSureCancel(Context context, boolean cancelable, DialogInterface.OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
        initView();
    }

    public RxDialogWriteSureCancel(Context context) {
        super(context);
        initView();
    }

    public RxDialogWriteSureCancel(Context context, float alpha, int gravity) {
        super(context, alpha, gravity);
        initView();
    }

    public TextView getSureView() {
        return mTvSure;
    }

    public void setSureListener(View.OnClickListener listener) {
        mTvSure.setOnClickListener(listener);
    }

    public TextView getCancelView() {
        return mTvCancel;
    }

    public void setCancelListener(View.OnClickListener listener) {
        mTvCancel.setOnClickListener(listener);
    }
    public void setdialogTvWriteShoesTypeValueListener(View.OnClickListener listener) {
        dialogLlWriteShoesType.setOnClickListener(listener);
    }
    public void setdialogTvWriteSerialTypeValueListener(View.OnClickListener listener) {
        dialogLlWriteSerialType.setOnClickListener(listener);
    }
    public void setdialogTvWriteShoesColorValueListener(View.OnClickListener listener) {
        dialogLlWriteShoesColor.setOnClickListener(listener);
    }
    public void setdialogTvWriteShoesSizeValueListener(View.OnClickListener listener) {
        dialogLlWriteShoesSize.setOnClickListener(listener);
    }

    public void setdialogLlWriteCompanyListener(View.OnClickListener listener) {
        dialogLlWriteCompany.setOnClickListener(listener);
    }
    public void setdialogLlWriteCodeWordListener(View.OnClickListener listener) {
        dialogLlWriteCodeWord.setOnClickListener(listener);
    }
    public void setdialogLlWriteSpecificationListener(View.OnClickListener listener) {
        dialogLlWriteSpecification.setOnClickListener(listener);
    }
    public void setDialogTvWriteFootTypeLeftListener(View.OnClickListener listener) {
        dialogTvWriteFootTypeLeft.setOnClickListener(listener);
    }
    public void setDialogTvWriteFootTypeRightListener(View.OnClickListener listener) {
        dialogTvWriteFootTypeRight.setOnClickListener(listener);
    }
    public TextView getContentView() {
        return mTvContent;
    }

    public void setSure(String content) {
        mTvSure.setText(content);
    }

    public void setCancel(String content) {
        if (!TextUtils.isEmpty(content)) {
            mTvCancel.setText(content);
        } else {
            mTvCancel.setVisibility(View.GONE);
            mViewLine.setVisibility(View.GONE);
        }
    }

    public void setContent(String str) {
        mTvContent.setText(str);
    }

    public void setTitle(String str) {
        if (!TextUtils.isEmpty(str)) {
            mTvTitle.setVisibility(View.VISIBLE);
            mTvTitle.setText(str);
        }
    }

    private void initView() {
        View dialogView = LayoutInflater.from(getContext()).inflate(R.layout.dialog_write_sure_cancel, null);
        mTvSure = dialogView.findViewById(R.id.tv_sure);
        mTvCancel = dialogView.findViewById(R.id.tv_cancel);
        mTvContent = dialogView.findViewById(R.id.tv_content);
        mTvTitle = dialogView.findViewById(R.id.tv_title);
        mViewLine = dialogView.findViewById(R.id.view_line);
        mTvCancel.setOnClickListener(v -> dismiss());
//        mTvContent.setMovementMethod(ScrollingMovementMethod.getInstance());
//        mTvContent.setTextIsSelectable(true);
        dialogTvWriteShoesTypeValue = dialogView.findViewById(R.id.dialog_tv_write_shoes_type_value);
        dialogTvWriteSerialTypeValue = dialogView.findViewById(R.id.dialog_tv_write_serial_type_value);
        dialogTvWriteShoesColorValue = dialogView.findViewById(R.id.dialog_tv_write_shoes_color_value);
        dialogTvWriteShoesSizeValue = dialogView.findViewById(R.id.dialog_tv_write_shoes_size_value);
        dialogLlWriteShoesType = dialogView.findViewById(R.id.dialog_ll_write_shoes_type);
        dialogLlWriteSerialType = dialogView.findViewById(R.id.dialog_ll_write_serial_type);
        dialogLlWriteShoesColor = dialogView.findViewById(R.id.dialog_ll_write_shoes_color);
        dialogLlWriteShoesSize = dialogView.findViewById(R.id.dialog_ll_write_shoes_size);
        dialogLlWriteCompany = dialogView.findViewById(R.id.dialog_ll_write_company);
        dialogTvWriteCompanyValue = dialogView.findViewById(R.id.dialog_tv_write_company_value);
        dialogLlWriteCodeWord = dialogView.findViewById(R.id.dialog_ll_write_code_word);
        dialogTvWriteCodeWordValue = dialogView.findViewById(R.id.dialog_tv_write_code_word_value);
        dialogLlWriteSpecification = dialogView.findViewById(R.id.dialog_ll_write_specification);
        dialogTvWriteSpecificationValue = dialogView.findViewById(R.id.dialog_tv_write_specification_value);
        dialogTvWriteFootTypeValue = dialogView.findViewById(R.id.dialog_tv_write_foot_type_value);
        dialogTvWriteFootTypeLeft = dialogView.findViewById(R.id.dialog_tv_write_foot_type_left);
        dialogTvWriteFootTypeRight = dialogView.findViewById(R.id.dialog_tv_write_foot_type_right);

        ivDialogTvWriteCompany = dialogView.findViewById(R.id.iv_dialog_tv_write_company);
        ivDialogTvWriteCodeWord = dialogView.findViewById(R.id.iv_dialog_tv_write_code_word);
        ivDialogTvWriteShoesType = dialogView.findViewById(R.id.iv_dialog_tv_write_shoes_type);
        ivDialogTvWriteSerialType = dialogView.findViewById(R.id.iv_dialog_tv_write_serial_type);
        ivDialogTvWriteShoesColor = dialogView.findViewById(R.id.iv_dialog_tv_write_shoes_color);
        ivDialogTvWriteShoesSize = dialogView.findViewById(R.id.iv_dialog_tv_write_shoes_size);
        ivDialogTvWriteSpecification = dialogView.findViewById(R.id.iv_dialog_tv_write_specification);


        setContentView(dialogView);
    }
}